﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Estsh.Core.Base;
using Estsh.Core.Wms.IRepositories;
using Estsh.Core.Wms.IServices;
using Estsh.Core.Model.Result;
using Estsh.Core.Services;
using Estsh.Core.Repositories;
using Estsh.Core.Models;
using Newtonsoft.Json.Linq;
using Estsh.Core.Model.EnumUtil;

namespace Estsh.Core.Wms.Services
{
    public class SemiFinishInStockService : BaseService<BaseEntity>, ISemiFinishInStockService
    {
        private readonly ISemiFinishInStockRepository repository;
        public SemiFinishInStockService(ISemiFinishInStockRepository _repository) : base(_repository)
        {
            repository = _repository;
        }

        public string CheckRK(string RKNO)
        {
            List<WmsRack> wmsRack = repository.GetRackNo(RKNO);
            //判断库内有此条码记录
            if (wmsRack.Count > 0)
            {
                if (wmsRack[0].Enabled == "N")
                {
                    return "[" + RKNO + "]:料架车已冻结，请检查!";
                }

                //List<SysStock> cartonInfo = repository.CheckCartonNoStatus(RKNO);

                //if (cartonInfo.Count > 0)
                //{
                //    return "[" + RKNO + "]:料架车不可用，请检查!";
                //}

                //料架车可用
                return "OK";
            }
            else
            {
                return "[" + RKNO + "]:在未找到架车号，请检查!";
            }

        }

        public string checkProduct(string productNo)
        {
            List<SysStock> cartonInfo = repository.CheckCartonNoStatus(productNo);

            if (cartonInfo.Count == 0)
            {
                return "[" + productNo + "]:产品条码不存在，请检查!";
            }
            if (cartonInfo[0].Enabled == "N")
            {
                return "[" + productNo + "]:产品条码不可用，请检查!";
            }
            if (cartonInfo[0].PartPackage == null || cartonInfo[0].PartPackage.ToString() == "")
            {
                return "[" + productNo + "]:产品条码未维护默认包装，请检查!";
            }


            return "OK" + cartonInfo[0].PartPackage;
        }

        public string UpdateStock(string locateName, string RKno, string productNo, string Num, string loginId)
        {

            return repository.Insertinfo(locateName, RKno, productNo, Num, loginId);
        }
    }
}
